package servlet;

import pojo.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet (urlPatterns="/add")
public class AddUserServlet extends HttpServlet {
    public void addUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserService userService = (UserService) new UserServiceImpl();
        req.setCharacterEncoding("utf-8");
        String name=req.getParameter("name");
        String pass=req.getParameter("pass");
        int result=userService.addUser(new User(name,pass));
        resp.sendRedirect("user");

    }
}

